package com.example.neutonote2.viewmodel;

import android.app.Application;
import androidx.lifecycle.AndroidViewModel;
import androidx.lifecycle.LiveData;
import java.util.List;

import com.example.neutonote2.data.model.Tag;
import com.example.neutonote2.data.repository.TagRepository;

/**
 * 标签的ViewModel，用于管理UI相关的标签数据
 */
public class TagViewModel extends AndroidViewModel {
    private final TagRepository repository;
    private final LiveData<List<Tag>> allTags;

    public TagViewModel(Application application) {
        super(application);
        repository = new TagRepository(application);
        allTags = repository.getAllTags();
    }

    // 获取所有标签
    public LiveData<List<Tag>> getAllTags() {
        return allTags;
    }

    // 按ID获取标签
    public LiveData<Tag> getTagById(int id) {
        return repository.getTagById(id);
    }
    
    // 获取笔记的所有标签
    public LiveData<List<Tag>> getTagsForNote(int noteId) {
        return repository.getTagsForNote(noteId);
    }

    // 插入标签
    public void insert(Tag tag) {
        repository.insert(tag);
    }

    // 更新标签
    public void update(Tag tag) {
        repository.update(tag);
    }

    // 删除标签
    public void delete(Tag tag) {
        repository.delete(tag);
    }
    
    // 添加标签到笔记
    public void addTagToNote(int noteId, int tagId) {
        repository.addTagToNote(noteId, tagId);
    }
    
    // 从笔记中移除标签
    public void removeTagFromNote(int noteId, int tagId) {
        repository.removeTagFromNote(noteId, tagId);
    }
    
    // 移除笔记的所有标签
    public void removeAllTagsFromNote(int noteId) {
        repository.removeAllTagsFromNote(noteId);
    }
    
    // 清理无效标签
    public void cleanInvalidTags() {
        repository.cleanInvalidTags();
    }
} 